#ifndef _FILE_FINDER_H
#define _FILE_FINDER_H


#include <Windows.h>
#include <strsafe.h>
#include "Minecraft\Containers\Chunk.h"

void FileFinder(char* path);

char self[2] = ".";
char parent[3] = "..";

void FileFinder(char* path)
{
	WIN32_FIND_DATA outData;
	HANDLE hFind = INVALID_HANDLE_VALUE;

	char filePath[MAX_PATH];
	StringCchCopy(filePath, MAX_PATH, path);
	StringCchCat(filePath, MAX_PATH, "*");

	//we've found the first file in here (which is probably the . folder)
	hFind =	FindFirstFile(filePath , &outData);
	if(hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			//you got a directory that's not a garbage directory
			if (outData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(outData.cFileName, self) != 0 && strcmp(outData.cFileName, parent) != 0)
			{
				char nextFolder[MAX_PATH];
				StringCchCopy(nextFolder, MAX_PATH, path);
				StringCchCat(nextFolder, MAX_PATH, outData.cFileName);
				StringCchCat(nextFolder, MAX_PATH, "\\");
				FileFinder(nextFolder);
			}
			//you got a file
			else
			{
				if(strcmp(outData.cFileName, self) != 0 && strcmp(outData.cFileName, parent) != 0)
				{
					Chunk testJerk;
					testJerk.LoadFromNBT(outData.cFileName);
				}
				//do whatever you want with the file
			}
		}
		while(FindNextFile(hFind, &outData) != 0);
	}
	FindClose(hFind);
}

#endif